<template>
    <div class="parbox">
        <div class="box1">
            <basic-form
                :showAlert="false"
                message="请先填写基本信息提交保存后，再上传证照扫描图片"
                :isBtn="false"
                :formInfos="s_FormInfo"
                :formDatas="s_formDatas"
                :rules="s_rules"
                ref="forms"
                @onSubmit="onSubmit"
                @onChangeType="onChangeType"
            ></basic-form>
        </div>
        <div class="box2">
            <a-button class="btn"  type="primary"  @click="nexts()">
                下一步
            </a-button>
        </div>
    </div>
</template>

<script>
import basicForm from '../common/basicForm'
import {saveInfo } from './regisLicense'
export default {
  props: {
  },
  components: {
    basicForm,
  },
  data() {
    return {
      s_FormInfo: [
        { label: '证照类型', name: 'zhengZhaolx', type: 'dicselect',dicName:'zhuCezlx', placeholder: '请选择' },
        { label: '产品名称', name: 'chanPinmc', type: 'input', placeholder: '请选择', },
        { label: '包装规格', name: 'baoZhuanggg', type: 'input', placeholder: '请选择', },
        { label: '产品是否进口', name: 'laiYuanlx',  type: 'dicselect',dicName:'laiYuanlx', placeholder: '请选择', },
        { label: '生产商代码', name: 'shengChancsdm', type: 'input', placeholder: '请输入' },
        { label: '生产商名称', name: 'shengChancsmc', type: 'input', placeholder: '请输入' },
        { label: '生产商地址', name: 'shengChancszs', type: 'input', placeholder: '请输入' },
        { label: '证照号码', name: 'zhengZhaohm', type: 'input', placeholder: '请输入' },
        { label: '证照说明', name: 'zhengZhaosm', type: 'textarea', placeholder: '请输入' },
        { label: '证照备注', name: 'zhengZhaobz', type: 'textarea', placeholder: '请输入' },
        { label: '颁发机构', name: 'banFajg', type: 'input', placeholder: '请输入' },
        { label: ['有效期','到'], name: ['youXiaoqs','youXiaoqz'], type: 'datatimeR', placeholder: '请输入' },
        // { label: '预警日期', name: 'yuJingrq', type: 'datatime', placeholder: '请输入' },
        { label: '状态', name: 'zhuangTai',  type: 'dicselect',dicName:'zhuCezzt',  placeholder: '请选择',},
        { label: ['保存', '重置'], type: 'botton' }
      ],
      s_formDatas: {
        sysSeq: 0,
        pid: null,
        zhengZhaofl: null,
        zhengZhaolx: null,
        suoShupmc: null,
        suoShupdm: null,
        zhengZhaohm: null, 
        banFajg: null,
        youXiaoqs: null,
        youXiaoqz: null,
        yuJingrq: null,
        zhuangTai:  '2',
        suoShupPid: null
      },
      s_rules: {
        suoShupPid: [{ required: true, message: '客户必须选择', trigger: 'blur' }],
        zhengZhaolx: [{ required: true, message: '证照类型必填', trigger: 'blur' }],
        zhengZhaohm: [{ required: true, message: '证照号码必填', trigger: 'change' }],
        youXiaoqs: [{ required: true, message: '有效期起始时间必填', trigger: 'change' }],
        youXiaoqz: [{ required: true, message: '有效期到期时间必填', trigger: 'change' }],
      },
      isSubmit:false
    }
  },
  created(){

  },
  mounted() {
    console.log("000000000");
    this.s_formDatas = {
        sysSeq: 0,
        pid: null,
        laiYuanlx: '国产',
        zhengZhaofl: null,
        zhengZhaolx: null,
        suoShupmc: null,
        suoShupdm: null,
        zhengZhaohm: null, 
        banFajg: null,
        youXiaoqs: null,
        youXiaoqz: null,
        yuJingrq: null,
        zhuangTai: '正常',
        suoShupPid: null
    }
  },
  methods: {
    nexts(){
        this.$refs.forms.submitForm()
    },
    onSubmit(val) {
      if(this.isSubmit){
          this.$emit('nextStep')
      }else{
        this.saveObjInfo(val)
      }
      
    },
    // 保存详细信息
    async saveObjInfo(val) {
      // this.$message.loading({ content: '提交中'， })
      let res = await saveInfo(val)
      console.log(res)
      if (res && res.code && res.code === 'C1' && res.data) {
        this.$message.success({ content: '保存成功', duration: 2 })
        this.isSubmit=true;
        let zzid={
            pid:res.data.pid,
            zhengZhaotpPid:res.data.zhengZhaotpPid,
            sysSeq:res.data.sysSeq,
            zhengZhaolx:res.data.zhengZhaolx
        }
        this.$emit('nextStep',zzid)
      } else {
        this.$message.error({ content: '保存失败', duration: 2 })
      }
    },
        // 表单编号
    onChangeType(name, val) {
      const _this = this
      switch (name) {
        case 'xiaoShoucpPid':
          _this.getSaleGoodsInfo(val)
          break
        case 'keHuPid':
          _this.getCustomerInfo(val)
          break
        case 'zhongBiaolx':
          _this.s_formDatas.zhongBiaolx = val
          break
        case 'laiYuanlx':
          _this.s_formDatas.laiYuanlx = val
          break
      }
    },
  },
}
</script>

<style scoped>

</style>